package com.jctrip.hotel.source.service.hworld;

import com.jctrip.hotel.source.client.HworldH5Client;
import com.jctrip.hotel.source.model.hworld.req.HworldAddUserReq;
import com.jctrip.hotel.source.model.hworld.req.HworldDeleteUserReq;
import com.jctrip.hotel.source.model.hworld.req.HworldModifyUserReq;
import com.jctrip.hotel.source.model.hworld.req.HworldQueryUserReq;
import com.jctrip.hotel.source.model.hworld.resp.HworldHotelInfo;
import com.jctrip.hotel.source.model.hworld.resp.HworldQueryUserResp;
import com.jctrip.hotel.source.model.hworld.resp.HworldResult;
import com.jctrip.hotel.source.service.hworld.impl.HworldServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Base64;
import java.util.List;

/**
 * @Author：Haruhi
 * @description:
 * @Date：2023/12/28 15:18
 * @Package：com.jctrip.hotel.source.service.hworld
 * @Project：hotel-main
 */
@Service
@Slf4j
public class HworldH5Service {

    @Resource
    private HworldH5Client hworldH5Client;
    @Resource
    private HworldService hworldService;

    public Boolean addUser(HworldAddUserReq req) {
        String token = hworldService.tokenCache(req.getCardId(), req.getCardPassWord());
        HworldResult<Boolean> hworldResult = hworldH5Client.addUser(token, req);
        if (null == hworldResult) {
            return null;
        }
        if (200 != hworldResult.getCode()) {
            throw new RuntimeException(hworldResult.getMessage());
        }
        return hworldResult.getContent();
    }

    public Boolean modifyUser(HworldModifyUserReq req) {
        String token = hworldService.tokenCache(req.getCardId(), req.getCardPassWord());
        HworldResult<Boolean> hworldResult = hworldH5Client.modifyUser(token, req);
        if (null == hworldResult) {
            return null;
        }
        if (200 != hworldResult.getCode()) {
            throw new RuntimeException(hworldResult.getMessage());
        }
        return hworldResult.getContent();
    }

    public Boolean deleteUser(HworldDeleteUserReq req) {
        String token = hworldService.tokenCache(req.getCardId(), req.getCardPassWord());
        HworldResult<Boolean> hworldResult = hworldH5Client.deleteUser(token, req);
        if (null == hworldResult) {
            return null;
        }
        if (200 != hworldResult.getCode()) {
            throw new RuntimeException(hworldResult.getMessage());
        }
        return hworldResult.getContent();
    }

    public HworldQueryUserResp queryUser(HworldQueryUserReq req) {
        String token = hworldService.tokenCache(req.getCardId(), req.getCardPassWord());
        HworldResult<HworldQueryUserResp> hworldResult = hworldH5Client.queryUser(token, req);
        if (null == hworldResult) {
            return null;
        }
        if (200 != hworldResult.getCode()) {
            throw new RuntimeException(hworldResult.getMessage());
        }
        return hworldResult.getContent();
    }

}
